package util;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 负责获取mybatis SqlSession
 * 
 * @author 赵政强
 *
 */
public class MybatisSessionFactory {

	private final static String RESOURCE_PATH = "mybatis-config.xml";
	private static SqlSessionFactory sqlSessionFactory;
	private static Reader reader;

	static {
		try {
			reader = Resources.getResourceAsReader(RESOURCE_PATH);
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static SqlSessionFactory getSession() {
		return sqlSessionFactory;
	}

	public static SqlSession openSession() {
		return sqlSessionFactory.openSession();
	}

	public static SqlSession openSession(boolean bool) {
		return sqlSessionFactory.openSession(bool);
	}
}
